package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdd.ehe.entity.Permission;
import com.zdd.ehe.entity.UserRole;
import com.zdd.ehe.mapper.UserRoleMapper;
import com.zdd.ehe.service.IUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-03-13
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {
    @Resource
    private UserRoleMapper userRoleMapper;


    /**
     * 分页查询用户角色列表
     *
     * @param page
     * @return
     */
    @Override
    public Page<UserRole> getAllUserRoleByPage(Page<UserRole> page) {
        Page<UserRole> pagex = userRoleMapper.getAllUserRoleByPage(page);
        return pagex;
    }

    /**
     * 新增用户角色权限
     *
     * @param userRole
     * @return
     */
    @Override
    public int insert(UserRole userRole) {
        return userRoleMapper.insert(userRole);
    }

    /**
     * 多表查询
     * @param userName
     * @return
     */
    @Override
    public List<UserRole> getAllByUserName(String userName){
        String user_name = "%" + userName + "%";
        return userRoleMapper.getAllByUserName(user_name);
    }

    /**
     * 根据userId 删除userrole
     * @param userId
     * @return
     */
    @Override
    public int deleteById(int userId){
        return userRoleMapper.deleteById(userId);
    }

    /**
     * 根据userId 查询 roleId列表
     * @param userId
     * @return
     */
    @Override
    public List<Integer> getRoleIdByUserId(int userId){
        return userRoleMapper.getRoleIdByUserId(userId);
    }

}
